import pyodbc

class databaseOperations:
    def __init__(self, server, user, password, database, charset, tds_version):
        self.server = server
        self.user = user
        self.password = password
        self.database = database
        self.charset = charset
        self.tds_version = tds_version

        # 使用获取到的参数构建连接字符串
        self.conn = pyodbc.connect(f'DRIVER={{SQL Server}};SERVER={server};DATABASE={database};UID={user};PWD={password}')

    def query(self, query_statement):
        cursor = self.conn.cursor()
        cursor.execute(query_statement)
        rows = cursor.fetchall()
        print(rows)
        return rows

    def updateQuery(self, update_statement):
        cursor = self.conn.cursor()
        cursor.execute(update_statement)
        # 可以根据需要获取受影响的行数等信息
        self.conn.commit()

    def close_connection(self):
        self.conn.close()